package com.gcl.rabbitmq;

import com.gcl.rabbitmq.utils.RabbitmqUtil;
import com.rabbitmq.client.Channel;

import java.io.IOException;
import java.util.Scanner;
import java.util.concurrent.TimeoutException;

public class Producer {

    //  队列名称

    public static final String QUEUE_NAME = "Hello Word";


    public static void main(String[] args) throws IOException, TimeoutException {
        // 获取信道

        Channel channel = RabbitmqUtil.getRabbitmqChannel();

        // 创建队列
        channel.queueDeclare(QUEUE_NAME,false,false,false,null);

        // 获取输入字符

        Scanner scanner = new Scanner(System.in);

        while (scanner.hasNext()){
            String message = scanner.next();
            channel.basicPublish("",QUEUE_NAME,null,message.getBytes());
            System.out.println("发送消息完成:"+message);

        }

    }
}
